<?php

namespace app\user\model;

use think\Model;
use Carbon\Carbon;
use app\common\traits\model\TraitModel;

class Intergrateadds extends Model
{

    protected $table = 'intergrateadd';
    
    use TraitModel;

    public function createIntergrateadd($intergrateadd_info)
    {
        return self::create($intergrateadd_info, true);
    }

    public function getOrderInfo($order_id)
    {
    	return self::get($order_id);
    }
    public function completeOrderPay($order_id)
    {
        if ($order = $this->getOrderInfo(['order_num' => $order_id])) {
            $this->startTrans();
            try {
                model('user/Intergrates')->addIntergrates($order->intergrate, $order->user_id, ['remark' => '充值']);

                $order->status = 1;//完成支付进入待入住
                $order->paid_at = Carbon::now()->toDateTimeString();//支付时间
                $order->save();
                $this->commit();
            } catch (\Exception $e) {
                $this->rollback();
                return false;
            }
            return true;
        } 
        return false;
    }

}